1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : teams/classes/class.teamartefacts.inc.php
5 : - Modulgruppe: Teams
6 : - Beschreibung: Verwaltung der Zuordnung von Elementen (Forenbeiträge, Ressourcen...) zu Teams.
7 : - Version: 0.1, 26/03/06
8 : - Autor(en): Clemens Weiß <clemens.weiss@mni.fh-giessen.de>
9 : +---------------------------------------------------------------------------+
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or any later version.
14 : +---------------------------------------------------------------------------+
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 : +--------------------------------------------------------------------------*/
23 : /**
24 : * Verwaltung der Zuordnung von Elementen (Forenbeiträge, Ressourcen...) zu Teams.
25 : * @package eStudy.Teams
26 : * @version 0.1, 26/03/06
27 : * @author Clemens Weiß <clemens.weiss@mni.fh-giessen.de>
28 : */
29 : // Hier werden die gleichen Konstanten wie im Rollenspiel verwendet, damit es
30 : // keine Konflikte gibt, wenn beide Klassen eingebunden werden.
31 1 : if (!defined("FORUM")) define("FORUM", 1);
32 : //define("PM", 2);
33 : //define("ANNOUNCEMENT", 3);
34 1 : if (!defined("RESSOURCE")) define("RESSOURCE", 4);
35 : //define("NEWS_OF_THE_DAY", 5);
36 1 : require_once ("class.team.inc.php");
37 1 : class TeamArtefacts {
38 : /**
39 : * Gibt zu einem Element (Forenbeitrag oder Ressource)
40 : * das Team zurück.
41 : *
42 : * @static
43 : * @access public
44 : * @param int $cat Kategorie, zu der das Element gehört (FORUM - Forumpost,
45 : * RESSOURCE - Link, Datei oder Ordner im Ressourcenmanager)
46 : * @param int $item ID des Elements
47 : * @return mixed Teamobjekt oder false
48 : */
49 : function getTeamForItem($cat, $item) {
50 0 : global $db, $settings;
51 0 : $dbp = $settings["dbPrefix"];
52 0 : if (strval(intval($cat)) != $cat || strval(intval($item)) != $item) {
53 0 : return false;
54 : }
55 0 : $teamID = intval($db->get_var("SELECT team_id FROM {$dbp}team_artefacts WHERE category='$cat' AND item_id='$item'"));
56 0 : if ($teamID > 0) {
57 0 : return new Team($teamID);
58 : }
59 0 : return false;
60 : }
61 : /**
62 : * Legt für ein Element (Forenbeitrag oder Ressource) fest,
63 : * dass es vom Mitglied eines Teams erstellt wurde.
64 : *
65 : * @static
66 : * @access public
67 : * @param int $cat Kategorie, zu der das Element gehört (FORUM - Forumpost,
68 : * RESSOURCE - Link, Datei oder Ordner im Ressourcenmanager)
69 : * @param int $item ID des Elements
70 : * @param int $team ID des Teams
71 : * @return bool true bei Erfolg, sonst false
72 : */
73 : function setTeamForItem($cat, $item, $team) {
74 0 : global $db, $settings, $EZSQL_ERROR;
75 0 : $dbp = $settings["dbPrefix"];
76 0 : if (strval(intval($cat)) != $cat || strval(intval($item)) != $item || strval(intval($team)) != $team) {
77 0 : return false;
78 : }
79 0 : $errorCount = count($EZSQL_ERROR);
80 0 : $db->query("REPLACE INTO {$dbp}team_artefacts SET category='$cat', item_id='$item', team_id='$team'");
81 0 : if (count($EZSQL_ERROR) > $errorCount) {
82 0 : return false;
83 : }
84 0 : return true;
85 : }
86 : /**
87 : * Löscht die Teamzuordnungen zu einem oder mehreren angegebenen Elementen.
88 : *
89 : * @static
90 : * @access public
91 : * @param int $cat Kategorie, zu der das Element gehört (FORUM - Forumpost,
92 : * RESSOURCE - Link, Datei oder Ordner im Ressourcenmanager)
93 : * @param mixed $item ID eines Elements (int) oder Array von IDs
94 : * @return bool true bei Erfolg, sonst false
95 : */
96 : function deleteItem($cat, $item) {
97 0 : global $db, $settings, $EZSQL_ERROR;
98 0 : $dbp = $settings["dbPrefix"];
99 0 : if (strval(intval($cat)) != $cat || !(strval(intval($item)) == $item || (is_array($item) && !empty($item)))) {
100 0 : return false;
101 : }
102 0 : if (is_array($item)) {
103 0 : $item = array_map("intval", $item);
104 0 : $itemSQL = "item_id IN (".implode(", ", $item) .")";
105 0 : } else {
106 0 : $itemSQL = "item_id='$item'";
107 : }
108 0 : $errorCount = count($EZSQL_ERROR);
109 0 : $db->query("DELETE FROM {$dbp}team_artefacts WHERE category='$cat' AND $itemSQL");
110 0 : if (count($EZSQL_ERROR) > $errorCount) {
111 0 : return false;
112 : }
113 0 : return true;
114 : }
115 : }
|